package com.florent37.runtimepermission3.slice;


import com.florent37.runtimepermission3.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;
import ohos.agp.components.Text;

public class RuntimePermissionMainActivityJava7Slice extends AbilitySlice {
    private final static String PERMISSION_READ_CONTEXTS = "ohos.permission.READ_CONTACTS";
    private final static String LOCATION = "ohos.permission.LOCATION";


    private Text resultText;
    private Component requestComponent;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_fragment_runtime_fragment_in);

        /*if (verifySelfPermission(PERMISSION_READ_CONTEXTS) != IBundleManager.PERMISSION_GRANTED) {
            requestPermissionsFromUser(
                    new String[]{"ohos.permission.WRITE_USER_STORAGE",LOCATION}, 123);

        }else {
            return;
        }*/

        resultText = (Text) findComponentById(ResourceTable.Id_resultView);
        requestComponent = findComponentById(ResourceTable.Id_requestView);

        requestComponent.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent newIntent = new Intent();
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.florent37.runtimepermission3")
                        .withAbilityName("com.florent37.runtimepermission3.AskPermission")
                        .build();
                newIntent.setOperation(operation);
                startAbility(newIntent);
            }
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
